home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / packages / rcompile.el.z / rcompile.el
Encoding:
Text File  |  1998-05-21  |  7.0 KB  |  198 lines

  1. ;;; rcompile.el --- run a compilation on a remote machine
  2.  
  3. ;; Copyright (C) 1993, 1994 Free Software Foundation, Inc.
  4.  
  5. ;; Author: Albert    <alon@milcse.rtsg.mot.com>
  6. ;; Maintainer: FSF
  7. ;; Created: 1993 Oct 6
  8. ;; Version: 1.1
  9. ;; Keywords: tools, processes
  10.  
  11. ;; This file is part of XEmacs.
  12.  
  13. ;; XEmacs is free software; you can redistribute it and/or modify it
  14. ;; under the terms of the GNU General Public License as published by
  15. ;; the Free Software Foundation; either version 2, or (at your option)
  16. ;; any later version.
  17.  
  18. ;; XEmacs is distributed in the hope that it will be useful, but
  19. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  20. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  21. ;; General Public License for more details.
  22.  
  23. ;; You should have received a copy of the GNU General Public License
  24. ;; along with XEmacs; see the file COPYING.  If not, write to the Free
  25. ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  26. ;; 02111-1307, USA.
  27.  
  28. ;;; Synched up with: FSF 19.34.
  29.  
  30. ;;; Commentary:
  31.  
  32. ;; This package is for running a remote compilation and using emacs to parse
  33. ;; the error messages. It works by rsh'ing the compilation to a remote host
  34. ;; and parsing the output. If the file visited at the time remote-compile was
  35. ;; called was loaded remotely (ange-ftp), the host and user name are obtained
  36. ;; by the calling ange-ftp-ftp-name on the current directory. In this case the
  37. ;; next-error command will also ange-ftp the files over. This is achieved
  38. ;; automatically because the compilation-parse-errors function uses
  39. ;; default-directory to build it's file names. If however the file visited was
  40. ;; loaded locally, remote-compile prompts for a host and user and assumes the
  41. ;; files mounted locally (otherwise, how was the visited file loaded).
  42.  
  43. ;; See the user defined variables section for more info.
  44.  
  45. ;; I was contemplating redefining "compile" to "remote-compile" automatically
  46. ;; if the file visited was ange-ftp'ed but decided against it for now. If you
  47. ;; feel this is a good idea, let me know and I'll consider it again.
  48.  
  49. ;;; Installation:
  50.  
  51. ;; To use rcompile, you also need to give yourself permission to connect to
  52. ;; the remote host.  You do this by putting lines like:
  53.  
  54. ;; monopoly alon
  55. ;; vme33
  56. ;;
  57. ;; in a file named .rhosts in the home directory (of the remote machine).
  58. ;; Be careful what you put in this file. A line like:
  59. ;;
  60. ;; +
  61. ;;
  62. ;; Will allow anyone access to your account without a password. I suggest you
  63. ;; read the rhosts(5) manual page before you edit this file (if you are not
  64. ;; familiar with it already) 
  65.  
  66. ;;; Code:
  67.  
  68. (provide 'rcompile)
  69. (require 'compile)
  70. ;;; The following should not be needed.
  71. ;;; (eval-when-compile (require 'ange-ftp))
  72.  
  73. ;;;; user defined variables
  74.  
  75. (defgroup remote-compile nil
  76.   "Run a compilation on a remote machine"
  77.   :group 'processes
  78.   :group 'tools)
  79.  
  80.  
  81. (defcustom remote-compile-host nil
  82.   "*Host for remote compilations."
  83.   :type '(choice string (const nil))
  84.   :group 'remote-compile)
  85.  
  86. (defcustom remote-compile-user nil
  87.   "User for remote compilations.
  88. nil means use the value returned by \\[user-login-name]."
  89.   :type '(choice string (const nil))
  90.   :group 'remote-compile)
  91.  
  92. (defcustom remote-compile-run-before nil
  93.   "*Command to run before compilation.
  94. This can be used for setting up environment variables,
  95. since rsh does not invoke the shell as a login shell and files like .login
  96. \(tcsh\) and .bash_profile \(bash\) are not run.
  97. nil means run no commands."
  98.   :type '(choice string (const nil))
  99.   :group 'remote-compile)
  100.  
  101. (defcustom remote-compile-prompt-for-host nil
  102.   "*Non-nil means prompt for host if not available from filename."
  103.   :type 'boolean
  104.   :group 'remote-compile)
  105.  
  106. (defcustom remote-compile-prompt-for-user nil
  107.   "*Non-nil means prompt for user if not available from filename."
  108.   :type 'boolean
  109.   :group 'remote-compile)
  110.  
  111. ;;;; internal variables
  112.  
  113. ;; History of remote compile hosts and users
  114. (defvar remote-compile-host-history nil)
  115. (defvar remote-compile-user-history nil)
  116.  
  117.  
  118. ;;;; entry point
  119.  
  120. ;;;###autoload
  121. (defun remote-compile (host user command)
  122.   "Compile the current buffer's directory on HOST.  Log in as USER.
  123. See \\[compile]."
  124.   (interactive
  125.    (let ((parsed 
  126.       ;; XEmacs change
  127.       (cond
  128.        ((featurep 'efs)
  129.         (efs-ftp-path default-directory))
  130.        ((featurep 'ange-ftp)
  131.         (if (fboundp 'ange-ftp-ftp-name)
  132.         (ange-ftp-ftp-name default-directory)
  133.           (ange-ftp-ftp-path default-directory)))
  134.        (t nil)))
  135.          host user command prompt)
  136.      (if parsed
  137.          (setq host (nth 0 parsed)
  138.                user (nth 1 parsed))
  139.        (setq prompt (if (stringp remote-compile-host)
  140.                         (format "Compile on host (default %s): "
  141.                                 remote-compile-host)
  142.                       "Compile on host: ")
  143.              host (if (or remote-compile-prompt-for-host
  144.                           (null remote-compile-host))
  145.                       (read-from-minibuffer prompt
  146.                                             "" nil nil
  147.                                             'remote-compile-host-history)
  148.                     remote-compile-host)
  149.              user (if remote-compile-prompt-for-user
  150.                       (read-from-minibuffer (format
  151.                                              "Compile by user (default %s)"
  152.                                              (or remote-compile-user
  153.                                                  (user-login-name)))
  154.                                             "" nil nil
  155.                                             'remote-compile-user-history)
  156.                     remote-compile-user)))
  157.      (setq command (read-from-minibuffer "Compile command: "
  158.                                          compile-command nil nil
  159.                                          '(compile-history . 1)))
  160.      (list (if (string= host "") remote-compile-host host)
  161.            (if (string= user "") remote-compile-user user)
  162.            command)))
  163.   (setq compile-command command)
  164.   (cond (user
  165.          (setq remote-compile-user user))
  166.         ((null remote-compile-user)
  167.          (setq remote-compile-user (user-login-name))))
  168.   (let* ((parsed
  169.       ;; XEmacs change
  170.       (cond
  171.        ((featurep 'efs)
  172.         (efs-ftp-path default-directory))
  173.        ((featurep 'ange-ftp)
  174.         (if (fboundp 'ange-ftp-ftp-name)
  175.         (ange-ftp-ftp-name default-directory)
  176.           (ange-ftp-ftp-path default-directory)))
  177.        (t nil)))
  178.          (compile-command
  179.           (format "%s %s -l %s \"(%scd %s; %s)\""
  180.           remote-shell-program
  181.                   host
  182.                   remote-compile-user
  183.                   (if remote-compile-run-before
  184.                       (concat remote-compile-run-before "; ")
  185.                     "")
  186.                   (if parsed (nth 2 parsed) default-directory)
  187.                   compile-command)))
  188.     (setq remote-compile-host host)
  189.     (save-some-buffers nil nil)
  190.     (compile-internal compile-command "No more errors")
  191.     ;; Set comint-file-name-prefix in the compilation buffer so
  192.     ;; compilation-parse-errors will find referenced files by ange-ftp.
  193.     (save-excursion
  194.       (set-buffer compilation-last-buffer)
  195.       (setq comint-file-name-prefix (concat "/" user "@" host ":")))))
  196.  
  197. ;;; rcompile.el ends here
  198.